import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const router = new Router({
  routes: [
    {
      path: '/',
      name: 'login',
      component: () => import('@/pages/login/login.vue')
    },
    {
      path: '/register',
      name: 'register',
      component: () => import('@/pages/login/register.vue')
    },
    {
      path: '/index',
      name: 'index',
      component: () => import('@/pages/home/index.vue')
    },
    {
      path: '/add',
      name: '新增儿童信息',
      component: () => import('@/pages/home/add.vue')
    },
    {
      path: '/fastappint',
      name: 'fastappint',
      component: () => import('@/pages/appoint/fastAppoint.vue'),
      meta: {
        keepAlive: true // 需要被缓存
      }
    },
    {
      path: '/record',
      name: 'record',
      component: () => import('@/pages/record/record.vue')
    },
    {
      path: '/addrecord',
      name: '新增异地接种记录',
      component: () => import('@/pages/record/addRecord.vue')
    },
    {
      path: '/vaccinedetails',
      name: 'vaccinedetails',
      component: () => import('@/pages/vaccine/details.vue')
    },
    {
      path: '/plan',
      name: '接种计划',
      component: () => import('@/pages/plan/index.vue')
    },
    {
      path: '/nursery',
      name: '入托/学查验',
      component: () => import('@/pages/check/nursery.vue')
    },
    {
      path: '/completed',
      name: '已完成接种查验',
      component: () => import('@/pages/check/completed.vue')
    },
    {
      path: '/appointment',
      name: '接种预约',
      component: () => import('@/pages/appoint/appointment.vue')
    },
    {
      path: '/bookeDetails',
      name: '预约详情',
      component: () => import('@/pages/appoint/bookeDetails.vue')
    },
    {
      path: '/personal',
      name: '个人中心',
      component: () => import('@/pages/home/personal.vue')
    },
    {
      path: '/childInfo',
      name: '儿童信息',
      component: () => import('@/pages/home/childInfo.vue')
    },
    {
      path: '/confirmation',
      name: '预约确认',
      component: () => import('@/pages/appoint/confirmation.vue')
    },
    {
      path: '/payorder',
      name: '支付订单',
      component: () => import('@/pages/appoint/payorder.vue')
    },
    {
      path: '/addOne',
      name: 'addOne',
      component: () => import('@/pages/home/addOne.vue')
    },
    {
      path: '/fastAppointDoctor',
      name: 'fastAppointDoctor',
      component: () => import('@/pages/appoint/fastAppointDoctor.vue')
    },
  ]
})




router.beforeEach((to, from, next) => {
  let userId=sessionStorage.getItem('userId');
  if (to.path !== '/' && to.path !== '/register' && !userId) {
    return next('/')
  }
  next()

})

export default router;
